package com.yunhe.xyxxgl.view.User;

import com.yunhe.xyxxgl.control.UserController;
import com.yunhe.xyxxgl.mode.User;

import java.util.Map;
import java.util.Scanner;
import java.util.function.BiConsumer;

/**
 * Created by Administrator on 2017/8/8 0008.
 */
public class UserList {
    public static int userListUI(){
        System.out.println("***************************学员信息管理系统-学员管理***************************");
        System.out.println("编号\t\t用户名\t\t真名\t\t类型");
        Map<String,User> teaMap =  UserController.getTeacherMap();
        Map<String,User> admMap =  UserController.getAdminMap();
        teaMap.forEach(new BiConsumer<String, User>() {
            @Override
            public void accept(String s, User user) {
                System.out.println(user.getId()+"\t\t"+user.getUserName()+"\t\t"+user.getRealName()+"\t\t"+user.getType());
            }
        });
        admMap.forEach(new BiConsumer<String, User>() {
            @Override
            public void accept(String s, User user) {
                System.out.println(user.getId()+"\t\t"+user.getUserName()+"\t\t"+user.getRealName()+"\t\t"+user.getType());
            }
        });
        System.out.println("1.添加/修改用户\t2.删除用户\t3.返回主页");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入操作码：");
        try{
            int i = sc.nextInt();
            if(i<1 || i>3){
                throw new Exception("操作码未识别！");
            }
            return i;
        }catch(Exception e){
            String msg = e.getMessage();
            System.out.println((null != msg) ? msg : "输入错误！");
            return userListUI();
        }
    }
}
